package com.itheima;

import java.util.ArrayList;
import java.util.Iterator;

public class ArrayListDemo {

    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("zhangsan");
        list.add("lisi");
        list.remove(1);

        String s = list.get(0);

        System.out.println(s);

        list.set(0,"wamgwu");

        System.out.println(list);


        list.add("zhangsan");
        list.add("lisi");
        list.add("wangwu");
        list.add("zhaoliu");

        System.out.println("---------------普通for循环--------------------");

        for (int i = 0; i < list.size(); i++) {
            String s1 = list.get(i);
            System.out.println(s1);
        }

        System.out.println("---------------增强for--------------------");
        for (String obj : list){
            System.out.println(obj);
        }

        System.out.println("---------------迭代器--------------------");
        Iterator<String> iterator = list.iterator();

        while (iterator.hasNext()){
            String s2 = iterator.next();
            System.out.println(s2);
        }

        System.out.println("----------------Lambda表达式-------------------");

        list.forEach((name)-> System.out.println(name));

        list.forEach(System.out::println);


    }
}
